package com.xr.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.xr.constant.MessageConstant;
import com.xr.result.Result;
import com.xr.service.MemberService;
import com.xr.service.ReportService;
import com.xr.service.SetMealService;
import com.xr.utils.DateUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/report")
public class ReportController {

    @Reference
    private MemberService memberService;

    @Reference
    private SetMealService setMealService;

    @Reference
    private ReportService reportService;

    //获取运营数据
    @RequestMapping("/getBusinessReportData")
    public Result getBusinessReportData() {
        try {
            //真实数据测试
            Map<String, Object> map = reportService.getBusinessReportData();
            return new Result(true, MessageConstant.GET_BUSINESS_REPORT_SUCCESS, map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new Result(true, MessageConstant.GET_BUSINESS_REPORT_FAIL);
    }

    //获取会员数量
    @RequestMapping("/getMemberReport")
    public Map getMemberReport() {
        Map<String, Object> map = new HashMap<>();
        List<String> months = DateUtils.getLastYear4Month("YYYY.MM");
        System.out.println(months);
        List<Integer> memberDateSum = memberService.getMemberDateSum(months);
        map.put("months", months);
        map.put("memberCount", memberDateSum);
        return map;
    }

    //获取套餐
    @RequestMapping("/getSetmealReport")
    public Result getSetmealReport() {
        try {
            List<Map<String, Object>> list = setMealService.findSetmealCount();
            return new Result(true, MessageConstant.GET_SETMEAL_COUNT_REPORT_SUCCESS, list);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new Result(true, MessageConstant.GET_SETMEAL_COUNT_REPORT_FAIL);
    }
}
